package io.xiyou.order.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.xiyou.order.api.IOrderService;
import io.xiyou.order.api.bo.AddOrderBO;
import io.xiyou.order.api.bo.PayOrderBO;
import io.xiyou.order.api.dto.OrderDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 订单接口
 *
 * @author 西柚
 * @date 2021-10-14 00:23:08
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/order")
@Api(value = "/order", tags = "订单接口")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @ApiOperation("创建订单")
    @PostMapping("/createOrder")
    public OrderDTO createOrder(@RequestBody AddOrderBO addOrderBO) {
        return orderService.createOrder(addOrderBO);
    }

    @ApiOperation("批量创建订单")
    @PostMapping("/batchCreateOrder")
    public void batchCreateOrder() {
        orderService.batchCreateOrder();
    }

    @ApiOperation("支付订单")
    @PostMapping("/payOrder")
    public void payOrder(@RequestBody PayOrderBO payOrderBO) {
        payOrderBO.setXid(payOrderBO.getOrderCode() + "_pay");

        orderService.payOrder(payOrderBO);
    }

    @ApiOperation("订单详情")
    @PostMapping("/getOrderDetails")
    @ApiImplicitParam(name = "orderCode", value = "订单号", required = true, dataType = "Long", paramType = "query")
    public OrderDTO getOrderDetails(@RequestParam("orderCode") Long orderCode) {
        return orderService.getOrderDetails(orderCode);
    }

}
